/*
 * Powered By [rapid-framework]
 * Web Site: http://www.rapid-framework.org.cn
 * Google Code: http://code.google.com/p/rapid-framework/
 * Since 2008 - 2012
 */

package com.tech15.pub.dao;

import java.util.*;

import javacommon.base.*;
import javacommon.util.*;

import cn.org.rapid_framework.util.*;
import cn.org.rapid_framework.web.util.*;
import cn.org.rapid_framework.page.*;
import cn.org.rapid_framework.page.impl.*;

import com.tech15.pub.model.*;
import com.tech15.pub.dao.*;
import com.tech15.pub.service.*;
import com.tech15.pub.vo.query.*;

/**
 * @author 胡作正 email:zuozhenghu@sina.com
 * @version 1.0
 * @since 1.0
 */


import static cn.org.rapid_framework.util.ObjectUtils.*;
import org.springframework.stereotype.Repository;

@Repository
public class PubWzcgDao extends BaseHibernateDao<PubWzcg,java.lang.String>{

	public Class getEntityClass() {
		return PubWzcg.class;
	}
	
	public Page findByPageRequest(PageRequest<Map> pageRequest) {
		//XsqlBuilder syntax,please see http://code.google.com/p/rapid-xsqlbuilder
		// [column]为字符串拼接, {column}为使用占位符. 以下为图方便采用sql拼接,适用性能要求不高的应用,使用占位符方式可以优化性能. 
		// [column] 为PageRequest.getFilters()中的key
		String sql = "select t from PubWzcg t where 1=1 "
				+ "/~ and t.sqrbh = '[sqrbh]' ~/"
				+ "/~ and t.sqrxm = '[sqrxm]' ~/"
				+ "/~ and t.bm = '[bm]' ~/"
				+ "/~ and t.gwzw = '[gwzw]' ~/"
				+ "/~ and t.gzlb = '[gzlb]' ~/"
				+ "/~ and t.ysqksm = '[ysqksm]' ~/"
				+ "/~ and t.xhgg = '[xhgg]' ~/"
				+ "/~ and t.xdrq = '[xdrq]' ~/"
				+ "/~ and t.cgzq = '[cgzq]' ~/"
				+ "/~ and t.yjdhrq = '[yjdhrq]' ~/"
				+ "/~ and t.hqbgsm = '[hqbgsm]' ~/"
				+ "/~ and t.sjdhrq = '[sjdhrq]' ~/"
				+ "/~ and t.yxj = '[yxj]' ~/"
				+ "/~ and t.ffdw = '[ffdw]' ~/"
				+ "/~ order by [sortColumns] ~/";
		return pageQuery(sql,pageRequest);
	}
	
	public Page findPage(PubWzcgQuery query) {
        //XsqlBuilder syntax,please see http://code.google.com/p/rapid-xsqlbuilder
        // [column]为字符串拼接, {column}为使用占位符. [column]为使用字符串拼接,如username='[username]',偷懒时可以使用字符串拼接 
        // [column] 为PageRequest的属性
		String sql = "select t from PubWzcg t where 1=1 "
			  	+ "/~ and t.sqrbh = {sqrbh} ~/"
			  	+ "/~ and t.sqrxm = {sqrxm} ~/"
			  	+ "/~ and t.bm = {bm} ~/"
			  	+ "/~ and t.gwzw = {gwzw} ~/"
			  	+ "/~ and t.gzlb = {gzlb} ~/"
			  	+ "/~ and t.ysqksm = {ysqksm} ~/"
			  	+ "/~ and t.xhgg = {xhgg} ~/"
				+ "/~ and t.xdrq >= {xdrqBegin} ~/"
				+ "/~ and t.xdrq <= {xdrqEnd} ~/"
			  	+ "/~ and t.cgzq = {cgzq} ~/"
				+ "/~ and t.yjdhrq >= {yjdhrqBegin} ~/"
				+ "/~ and t.yjdhrq <= {yjdhrqEnd} ~/"
			  	+ "/~ and t.hqbgsm = {hqbgsm} ~/"
				+ "/~ and t.sjdhrq >= {sjdhrqBegin} ~/"
				+ "/~ and t.sjdhrq <= {sjdhrqEnd} ~/"
			  	+ "/~ and t.yxj = {yxj} ~/"
			  	+ "/~ and t.ffdw = {ffdw} ~/"
				+ "/~ order by [sortColumns] ~/";
				
        //生成sql2的原因是为了不喜欢使用xsqlbuilder的同学，请修改生成器模板，删除本段的生成
        StringBuilder sql2 = new StringBuilder("select t from PubWzcg t where 1=1 ");
        if(isNotEmpty(query.getId())) {
            sql2.append(" and  t.id = :id ");
        }
        /*if(isNotEmpty(query.getSqrbh())) {
            sql2.append(" and  t.sqrbh = :sqrbh ");
        }*/
        if(isNotEmpty(query.getSqrbh())) {
            sql2.append(" and  t.sqrbh like '%"+query.getSqrbh()+"%'");
        }
        if(isNotEmpty(query.getSqrxm())) {
            sql2.append(" and  t.sqrxm = '"+query.getSqrxm()+"'");
        }
        if(isNotEmpty(query.getBm())) {
            sql2.append(" and  t.bm = :bm ");
        }
        if(isNotEmpty(query.getGwzw())) {
            sql2.append(" and  t.gwzw = :gwzw ");
        }
        if(isNotEmpty(query.getGzlb())) {
            sql2.append(" and  t.gzlb = :gzlb ");
        }
        if(isNotEmpty(query.getYsqksm())) {
            sql2.append(" and  t.ysqksm = :ysqksm ");
        }
        if(isNotEmpty(query.getXhgg())) {
            sql2.append(" and  t.xhgg = :xhgg ");
        }
        if(isNotEmpty(query.getXdrqBegin())) {
            sql2.append(" and  t.xdrq >= :xdrqBegin ");
        }
        if(isNotEmpty(query.getXdrqEnd())) {
            sql2.append(" and  t.xdrq <= :xdrqEnd ");
        }
        if(isNotEmpty(query.getCgzq())) {
            sql2.append(" and  t.cgzq = :cgzq ");
        }
        if(isNotEmpty(query.getYjdhrqBegin())) {
            sql2.append(" and  t.yjdhrq >= :yjdhrqBegin ");
        }
        if(isNotEmpty(query.getYjdhrqEnd())) {
            sql2.append(" and  t.yjdhrq <= :yjdhrqEnd ");
        }
        if(isNotEmpty(query.getHqbgsm())) {
            sql2.append(" and  t.hqbgsm = :hqbgsm ");
        }
        if(isNotEmpty(query.getSjdhrqBegin())) {
            sql2.append(" and  t.sjdhrq >= :sjdhrqBegin ");
        }
        if(isNotEmpty(query.getSjdhrqEnd())) {
            sql2.append(" and  t.sjdhrq <= :sjdhrqEnd ");
        }
        if(isNotEmpty(query.getYxj())) {
            sql2.append(" and  t.yxj = :yxj ");
        }
        if(isNotEmpty(query.getFfdw())) {
            sql2.append(" and  t.ffdw = :ffdw ");
        }
        if(isNotEmpty(query.getSortColumns())) {
            sql2.append(" order by :sortColumns ");
        }	
        
		return pageQuery(sql2.toString(),query);
	}
	

}
